from common.doLog import DoLog
dl = DoLog()
myLogger = dl.getLogger(__name__)
class DoYuanSuan:
    def jia(self,a, b):
        try:
            print("我要执行jia了")
            myLogger.info("我要执行jia了")
            if isinstance(a,(int,float)) and isinstance(b,(int,float)):
                c=a+b
                if isinstance(a,(float)) or isinstance(b,(float)):
                    c=round(c,2)
            else:
                return '非法输入'
        except AttributeError as a:
            print(f"我发生异常了，异常类型是{a}")
            myLogger.error(f"我发生异常了，异常类型是{a}")
        except Exception as A:
            print(f"我发生异常了，异常类型是{A}")
            myLogger.exception(f"我发生异常了，异常类型是{A}")
        else:
            print('未发生异常！')
            myLogger.info('未发生异常！')
            return c
        finally:
            print('不知道是否发生异常，运算已结束')
            myLogger.info('不知道是否发生异常，运算已结束')

    def jian(self,a, b):
        try:
            print("我要执行jian了")
            myLogger.info("我要执行jian了")

            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                c = a-b
                if isinstance(a, (float)) or isinstance(b, (float)):
                    c = round(c, 2)
            else:
                return '非法输入'
        except AttributeError as a:
            print(f"我发生异常了，异常类型是{a}")
            myLogger.error(f"我发生异常了，异常类型是{a}")
        except Exception as A:
            print(f"我发生异常了，异常类型是{A}")
            myLogger.exception(f"我发生异常了，异常类型是{A}")
        else:
            print('未发生异常！')
            myLogger.info('未发生异常！')
            return c
        finally:
            print('不知道是否发生异常，运算已结束')
            myLogger.info('不知道是否发生异常，运算已结束')

    def cheng(self,a, b):
        try:
            print("我要执行cheng了")
            myLogger.info("我要执行cheng了")
            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                c = a * b
                if isinstance(a, (float)) or isinstance(b, (float)):
                    c = round(c, 2)
            else:
                return '非法输入'
        except Exception as A:
            print(f"我发生异常了，异常类型是{A}")
            myLogger.exception(f"我发生异常了，异常类型是{A}")
        else:
            print('未发生异常！')
            myLogger.info('未发生异常！')
            return c
        finally:
            print('不知道是否发生异常，运算已结束')
            myLogger.info('不知道是否发生异常，运算已结束')


    def chu(self,a, b):
        try:
            print('我要执行chu了')
            myLogger.info('我要执行chu了')
            if b == 0:
                print('非法输入')
                return "非法输入"

            if isinstance(a, (int, float)) and isinstance(b, (int, float)):
                c = a / b

                if isinstance(a, (float)) or isinstance(b, (float)):
                    c = round(c,2)
            else:
                return '非法输入'
        except Exception as A:
            print(f"我发生异常了，异常类型是{A}")
            myLogger.exception(f"我发生异常了，异常类型是{A}")
        else:
            print('未发生异常！')
            myLogger.info('未发生异常！')
            return c
        finally:
            print('不知道是否发生异常，运算已结束')
            myLogger.info('不知道是否发生异常，运算已结束')
        return c

if __name__ == "__main__":
    a=DoYuanSuan()
    # a.jia(10,20)
    # a.jian(10,20)
    a.chu(10,0)
    # print(a.jia(10,20))
    # print(a.jian(10,20))
    # print(a.cheng(10,20))
    # print(a.chu(10,20))
